const mongoose = require('mongoose')

const Image = mongoose.model('Image')
const Comment = mongoose.model('Comment')

module.exports = () =>
Promise.all([
   Image.aggregate([{
        $group: {
            _id: 'total',
            images: {$sum: 1},
            views: {$sum: '$views'},
            likes: {$sum: '$likes'}
        }
    }]),
    Comment.count()
  ])
   .then(([[doc],count]) => ({
          images: doc ? doc.images : 0,
          views: doc ? doc.views : 0,
          likes: doc ? doc.likes : 0,
          comments: count
    }))
